﻿package net.wangit.framework.util;

import java.util.List;

import net.wangit.context.ActionContextHelper;
import net.wangit.context.LocalContext;
import net.wangit.context.Message;
import net.wangit.framework.session.AgileSession;


public class MessageUtil {

	public MessageUtil() {
	}

	public static String getMessage() {
		StringBuffer html = new StringBuffer();
		List systems = SystemMessage.getMessages();
		if (systems.size() > 0)
			systems.clear();
		setMessages(html, "MS", systems);
		AgileSession session = ActionContextHelper.getSession(LocalContext
				.getLocalContext().getActionContext());
		Message message = session.getMessage();
		if (message != null) {
			setMessages(html, "ME", message.getErrors());
			setMessages(html, "MI", message.getInfos());
		}
		return html.toString();
	}

	private static void setMessages(StringBuffer html, String css,
			List<String> messages) {
		for (int i = 0; i < messages.size(); i++) {
			html.append("<div class=\"").append(css).append("\">").append(
					messages.get(i)).append("</div>");
		}
	}
}
